package sel.me.spring.boot159.web.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author shenenlu 2020年12月25日 下午16:52:44
 */
@Slf4j
@Service
public class HystrixTestService {

    private AtomicInteger orderIdCounter = new AtomicInteger(0);

    public Integer queryByOrderId() {
        int c = orderIdCounter.getAndIncrement();
//        if ( log.isDebugEnabled() ) {
//            log.debug("orderIdCounter:{}", c);
//        }
//        if ( c < 10 ) {
//            try {
//                URL url = new URL("http://www.aaa.com");
//                URLConnection urlConnection = null;
//                urlConnection = url.openConnection();
//                urlConnection.setConnectTimeout(600);
//                urlConnection.setReadTimeout(8000);
//                urlConnection.getContent();
//            } catch (IOException e) {
//                throw new RuntimeException(e.getMessage());
//            }
//        }
        return c;
    }

    public void reset() {
        orderIdCounter.getAndSet(0);
    }



}
